package org.chen.controller;

import org.chen.common.CheckAds;
import org.chen.result.ResultBody;
import org.chen.service.CheckAdsService;
import org.chen.service_enum.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ads")
public class CheckAdsController {
    @Autowired
    private CheckAdsService checkAdsService;

    @PostMapping("/checkAds")
    private ResultBody<?> checkAds(@RequestParam String user_id,
                                   @RequestParam String ad_id,
                                   @RequestParam String reward_amount,
                                   @RequestParam String reward_type,
                                   @RequestParam String signature){
        CheckAds checkAds = new CheckAds();
        checkAds.setUser_id(user_id);
        checkAds.setAd_unit(ad_id);
        checkAds.setReward_amount(reward_amount);
        checkAds.setReward_item(reward_type);
        checkAds.setSignature(signature);
        boolean save = checkAdsService.save(checkAds);
        if (save){
            return ResultBody.success();
        }else {
            return ResultBody.error(ErrorCode.BAD_REQUEST.getCode(),ErrorCode.BAD_REQUEST.getMessage());
        }
    }
}
